import java.net.InetAddress;
import java.net.UnknownHostException;

public class LocalIPAddress {
    public static void main(String[] args) {
        try {
            // 获取本地主机的信息
            InetAddress localHost = InetAddress.getLocalHost();

            // 获取主机名
            String hostName = localHost.getHostName();

            // 获取IP地址
            String hostAddress = localHost.getHostAddress();

            System.out.println("主机名: " + hostName);
            System.out.println("IP地址: " + hostAddress);
        } catch (UnknownHostException e) {
            System.out.println("无法获取本地IP地址: " + e.getMessage());
        }
    }
}